import excel ${supp_data}/eitc_parameters/eitc_parameters_v2, firstrow sheet(clean) clear

foreach v of varlist *0 {
replace `v' = 0  if `v'==.
}

foreach v of varlist *2 {
local v1 = substr("`v'",1,length("`v'")-1)+"1"
capture noisily replace `v' = `v1'  if `v'==.
}
foreach v of varlist *3 {
local v1 = substr("`v'",1,length("`v'")-1)+"2"
capture noisily replace `v' = `v1'  if `v'==.
}

egen max_eitc = rowmax(eitc_maxc?)
gen maxd_eitc = eitc_maxc1-eitc_maxc0
gen maxd_eitc2 = eitc_maxc2-eitc_maxc1

gen year = taxyr_cut

merge m:1 year using ${supp_data}/cpi_u, keepusing(jan) gen(_m_cpi_u)
keep if year>=1970
replace taxyr_cut = year if taxyr_cut==.
rename jan cpi_jan
gen xxx = cpi_jan if year==2015
egen cpi_2015 = max(xxx)

foreach x in max_eitc maxd_eitc maxd_eitc2 eitc_maxcstart1 eitc_maxcstart2 {
gen `x'_iadj = `x'*(cpi_2015/cpi_jan)
}
gen p_income = maxd_eitc/eitc_maxcstart1
gen p_income2 = maxd_eitc2/eitc_maxcstart2

order taxyr_cut  maxd_eitc*_iadj p_income* eitc_maxcstart1* eitc_maxcstart2* max_eitc*_iadj max_eitc maxd_eitc

drop if year==2021
sort taxyr_cut
saveold ${supp_data}/eitc_params_yr, replace
